/**
 * Copyright 2011 BlueOxygen Technology
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.meruvian.demo.test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.apache.struts2.StrutsSpringTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.meruvian.demo.devcamp.entity.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author Dian Aditya
 * 
 */
@TestExecutionListeners
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/applicationContext.xml" })
public class PersonCrudTestCase extends StrutsSpringTestCase {
	private Person person = new Person();
	private EntityManager dao = null;

	@Before
	public void setUp() throws Exception {
		super.setUp();

		dao = applicationContext.getBean(EntityManagerFactory.class)
				.createEntityManager();
	}

	@Test
	public void testCrud() throws Exception {
		person.setFirstName("dian");
		person.setLastName("aditya");

		dao.persist(person);

		System.out.println("data ------> " + person.getId());
	}

	@After
	public void tearDown() throws Exception {
		dao.remove(person);

		dao.close();

		super.tearDown();
	}

}
